var timer = null;
var prevId = null;
var activeId = 1;
var slideImages = function(id, no_images, from)
{    
  id = (id < 1 ? no_images : id);
  id = (id > no_images ? 1 : id);
  activeId = id;
  var nextId = (id+1>no_images ? 1 : id+1);
  jQuery('#offer_image_'+id).fadeIn("slow");
  jQuery('#offer_image_'+id+'_control').addClass("active").removeClass("inactive");
  if(prevId && prevId != id)
  {
      jQuery('#offer_image_'+prevId).fadeOut("slow");
      jQuery('#offer_image_'+prevId+'_control').addClass("inactive").removeClass("active");
  }
  prevId = id;
  
  if (from == 'click')
  {
      clearTimeout(timer);
      timer = setTimeout('slideImages('+nextId+','+no_images+')', 5000);
  }
  else
  {
      timer = setTimeout('slideImages('+nextId+','+no_images+')', 4000);
  }
};

$(function() {
  $('#facebook-icon-button').qtip(
  {
    position:
    {
      corner:
      {
        target: 'bottomMiddle',
        tooltip: 'topMiddle'
      }
    },
    style:
    { 
      name: 'dark',
      tip:
      {
         corner: 'topMiddle',
         size:
         {
            x: 10,
            y : 8
         }
      },
      border:
      {
         width: 1,
         radius: 2
      }
    }
  });
  $('#twitter-icon-button').qtip(
  {
    position:
    {
      corner:
      {
        target: 'bottomMiddle',
        tooltip: 'topMiddle'
      }
    },
    style:
    { 
      name: 'dark',
      tip:
      {
         corner: 'topMiddle',
         size:
         {
            x: 10,
            y : 8
         }
      },
      border:
      {
         width: 1,
         radius: 2
      }
    }
  });
  $('#offer-button').qtip(
  {
    position:
    {
      corner:
      {
        target: 'bottomMiddle',
        tooltip: 'topMiddle'
      }
    },
    style:
    { 
      name: 'dark',
      tip:
      {
         corner: 'topMiddle',
         size:
         {
            x: 10,
            y : 8
         }
      },
      border:
      {
         width: 1,
         radius: 2
      }
    }
  });
  
  $('#search_query').qtip(
  {
    content: {
      text: '<b>Exemple:</b><br /><i>pizza bucuresti</i><br /><i>restaurant cluj</i><br /><i>spalatorie auto</i>'
    },
    position:
    {
      corner:
      {
        target: 'bottomMiddle',
        tooltip: 'topMiddle'
      }
    },
    style:
    { 
      name: 'dark',
      width: 120,
      'font-size': 11,
      tip:
      {
         corner: 'topMiddle',
         size:
         {
            x: 10,
            y : 8
         }
      },
      border:
      {
         width: 1,
         radius: 2
      }
    }
  });
});